<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Write Email</title>
</head>
<body>
    <h1>Write Email</h1>
    <form id="emailForm">
        <label for="recipient">收件人:</label>
        <input type="email" id="recipient" name="recipient" required>
    
        <label for="subject">主题:</label>
        <input type="text" id="subject" name="subject" required>
    
        <label for="content">内容:</label>
        <textarea id="content" name="content" rows="10" cols="30" required></textarea>
    
        <!-- 提交按钮，这里我们使用一个按钮来触发JavaScript函数，而不是真正的表单提交 -->
        <button type="button" onclick="getEmailData()">发送邮件</button>
    </form>
    <button onclick="goBack()">Back to Inbox</button>
    <script>
        function goBack() {
            // 发送消息给主进程，请求导航到收件箱
            window.electron.navigate('inbox');
        }
        function getEmailData() {
            // 获取输入框和文本域的值
            var recipient = document.getElementById('recipient').value;
            var subject = document.getElementById('subject').value;
            var content = document.getElementById('content').value;
            
            console.log('收件人:', recipient);
            console.log('主题:', subject);
            console.log('内容:', content);
            window.electronAPI.send('add-email', {
                recipient: recipient,
                subject: subject,
                content: content
            });
            window.electronAPI.receive("email-added", function(data) {
                window.electron.navigate('inbox');
            })
        }
    </script>
</body>
</html>